//
//  MallAddressTableViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/2.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallAddressTableViewCell.h"

#import "Address.h"
#import <Masonry.h>

@implementation MallAddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
//    CGSize size1 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(12)];
    CGSize size2 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(11)];
    CGSize size3 = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(10)];
    
    self.nickName.font = kUHSystemFontWithSize(12);
    self.phone.font = kUHSystemFontWithSize(12);
    self.address.font = kUHSystemFontWithSize(11);
    
//    
    self.address.frame = CGRectMake(10, self.nickName.y+self.nickName.height+5, SCREEN_WIDTH-20, size2.height);
    
//    self.line.backgroundColor = UISeparatedColorRGB;
    self.line.frame = CGRectMake(0, self.address.y+self.address.height+10, SCREEN_WIDTH, 1);
    
    [self.defaultAddress setImage:[IMAGE(@"login_un_tick") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.defaultAddress setTitle:@" 默认地址" forState:UIControlStateNormal];
    self.defaultAddress.titleLabel.font = kUHSystemFontWithSize(10);
    
    [self.editAddress setImage:[IMAGE(@"address_edit") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.editAddress setTitle:@" 编辑" forState:UIControlStateNormal];
    self.editAddress.titleLabel.font = kUHSystemFontWithSize(10);
    
    [self.deleteAddress setImage:[IMAGE(@"address_delete") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.deleteAddress setTitle:@" 删除" forState:UIControlStateNormal];
    self.deleteAddress.titleLabel.font = kUHSystemFontWithSize(10);
    
    
    self.defaultAddress.frame = CGRectMake(10, self.line.y+self.line.height+10, size3.width*2+size3.height+5, size3.height);
    CGFloat W = size3.width+5+size3.height;
    self.deleteAddress.frame = CGRectMake(SCREEN_WIDTH-10-W, self.defaultAddress.y, W, size3.height);
    self.editAddress.frame = CGRectMake(SCREEN_WIDTH-30-2*W, self.defaultAddress.y, W, size3.height);
    
    self.line2.backgroundColor = UISeparatedColorRGB;
    self.line2.frame = CGRectMake(0, self.defaultAddress.y+self.defaultAddress.height+10, SCREEN_WIDTH, 10);
    
    self.height = self.line2.y+10;
    
}
    
- (void)setModel:(Address *)model {
    if (_model != model) {
        _model = model;
        
        self.nickName.text = model.name;
        CGSize size1 = [LZCTools textSizeWithText:self.nickName.text font:self.nickName.font];
        self.nickName.frame = CGRectMake(10, 10, size1.width, size1.height);
        
        self.phone.text = model.mobile;
        self.phone.frame = CGRectMake(self.nickName.x+self.nickName.width+10, 10, SCREEN_WIDTH, size1.height);
        
        self.address.text = [NSString stringWithFormat:@"%@%@%@%@", model.province, model.city, model.district, model.detail];
        
        if (model.is_default == 1) {
            [self.defaultAddress setTitleColor:UIMainColorRGB forState:UIControlStateNormal];
            [self.defaultAddress setImage:[IMAGE(@"login_tick") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        }
        else {
            [self.defaultAddress setTitleColor:kGrayColor forState:UIControlStateNormal];
            [self.defaultAddress setImage:[IMAGE(@"login_un_tick") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        }
    }
}

- (CGFloat)cellHeight {
    return self.height;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
